package com.rybbaby.tss.front.tssAppUser.service.imp;

import com.rybbaby.tss.core.web.service.imp.BaseServiceImp;
import com.rybbaby.tss.front.tssAppUser.entity.TssAppUser;
import com.rybbaby.tss.front.tssAppUser.service.ITssAppUserService;
import com.rybbaby.tss.front.tssStudent.entity.TssStudent;
import com.rybbaby.tss.front.tssStudent.service.ITssStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

@Service
public class TssAppUsererviceImp extends BaseServiceImp<TssAppUser> implements ITssAppUserService {

    @Autowired
    private ITssStudentService studentService;

    @Override
    public Serializable register(TssAppUser appUser) {
        Serializable newId = this.save(appUser);
        if (newId != null) {
            //更新学APP端激活册状态
            List<TssStudent> students = studentService.findByProperty("headPortrait", appUser.getPhoneNum());
            if (students != null && !students.isEmpty()) {
                for (TssStudent student : students) {
                    student.setRegisterApp(true);
                }
                this.studentService.batchUpdate(students);
            }
        }
        return newId;
    }
}
